<?php

/**
* Front Controller
*/
class Front_Controller
{

private static $_instance = null;   
private $get = array() ;  
private $view;  // obj 
 

    private function __construct()
    {
        $validate = new Validator();
        $this->get = $validate->validateRequest($_REQUEST);
        $this->view = new View();
    } 
      
    /**
    * Запрет на клонирование
    * 
    */
    private function __clone() {}
       
    
    /**
    * Метод для вызова данного класса как singletone
    * 
    */
    public static function getInstance()
    {
     if( null == self::$_instance) { 
        self::$_instance = new Front_Controller();
    }
        return self::$_instance;
    }
  
    
    /**
    * RUN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    * 
    */
    
    public function run() 
    {
        $size = sizeof($this->get);
        if($size < 1 || empty($this->get['route'])) {     
        $actionController = Action_Controller_Fabric::getController("Index", $this->view, $this->get);
        } else {    
        switch ($this->get['route']) {
        case 'index': $actionController = Action_Controller_Fabric::getController("Index", $this->view, $this->get);
        break;
        case 'registration/': $actionController = Action_Controller_Fabric::getController("Registration", $this->view ,$this->get);
        break;
        case 'login/': $actionController = Action_Controller_Fabric::getController("Login", $this->view ,$this->get);        
        break;
        case 'personal/': $actionController = Action_Controller_Fabric::getController("Personal", $this->view, $this->get);
        break;
        case 'logout/' : $actionController = Action_Controller_Fabric::getController("Logout", $this->view, $this->get);
        break;
        case 'article/': $actionController = Action_Controller_Fabric::getController("Article", $this->view, $this->get);
        break;
        case 'about/': $actionController = Action_Controller_Fabric::getController("About", $this->view, $this->get);
        break;
        case 'add/': $actionController = Action_Controller_Fabric::getController("Add", $this->view, $this->get ); 
            // TODO: другие контролеры          
        break;
        default: 
        $actionController = Action_Controller_Fabric::getController("NotFound", $this->view, $this->get);       
        }
    } 
        
             
          // TODO: проверить на наличие объекта $actionController
          $actionController->run(); 
          $this->view->render();
            
          var_dump($actionController);
           //var_dump($this->get);
           //var_dump(session_get_cookie_params());
           //var_dump($_SESSION);
           //var_dump(session_get_cookie_params() );
    }
            
}
 
